﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace BPMS.Utility.Streams
{
    public static class StreamExtensions
    {
        public static byte[] ToBinary(this Stream stream)
        {
            using (MemoryStream memoryStream = new MemoryStream())
            {
                byte[] bufferBytes = new byte[1024 * 100];
                int readCount = stream.Read(bufferBytes, 0, bufferBytes.Length);
                while (readCount > 0)
                {
                    memoryStream.Write(bufferBytes, 0, readCount);
                    readCount = stream.Read(bufferBytes, 0, bufferBytes.Length);
                }
                return memoryStream.ToArray();
            }
        }
    }
}
